package com.bwsoft.util.ruanweisms;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

import com.bwsoft.api.service.impl.CodeServiceImpl;

public class RuanweiSmsUtil {
	private static Logger LOG = Logger.getLogger(RuanweiSmsUtil.class);
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
	static String str = sdf.format(new Date());
	public static String url = "http://121.52.209.124:8888/sms.aspx";
	public static String userid = "6122";
	public static String timestamp=str;	
	public static String sign=encryption("a10418952264"+str);
	public static String content = "尊敬的用户您好，您的短信验证码是：2457361。5分钟有效【优标检测】";
	public static String mobile = "";
	public static String account="a10418";
	public static String password="112233";


	public static String sendSms(String mobile,String code) {
		content="尊敬的用户您好，您的短信验证码是："+code+"。30分钟有效【优标检测】";
		LOG.info("向手机号为："+mobile+"发送短信，内容为："+content);
		String send = SmsClientSend.sendSms(url,"send",userid,timestamp,
				sign,mobile,content,account,password);
		return send;
	}
	
	public static String sendQCTipic(String mobile,String content){
		LOG.info("向手机号为："+mobile+"发送短信，内容为："+content);
		String send = SmsClientSend.sendSms(url,"send",userid,timestamp,
				sign,mobile,content,account,password);
		return send;
	}
	
	public static String encryption(String plain) {
		String re_md5 = new String(); 
		try { MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(plain.getBytes()); byte b[] = md.digest(); 
			int i; StringBuffer buf = new StringBuffer(""); 
			for (int offset = 0; offset < b.length; offset++)
			{ 
			i = b[offset];
			if (i < 0) i += 256; 
			if (i < 16) buf.append("0"); 
			buf.append(Integer.toHexString(i)); 
			}
			re_md5 = buf.toString();
		} catch(NoSuchAlgorithmException e)
		{ 
			e.printStackTrace();
		} 
		return re_md5; 
	} 
}
